<template>
  <div class="addPost">
    <el-dialog
      title="新增岗位"
      :center="true"
      :visible.sync="addDialogVisible"
      width="40%"
      :before-close="postCancel"
    >
      <el-form
        label-width="100px"
        :model="postList"
        :rules="rules"
        ref="postList"
      >
        <el-form-item label="岗位名称" prop="stationName">
          <el-input placeholder="岗位名称" v-model="postList.stationName"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="postCancel">取 消</el-button>
        <el-button type="primary" @click="addPost">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: "AddPost",
  props: ["addDialogVisible"],
  data() {
    return {
      postList: { stationName: "" },
      rules: {
        stationName: [{ required: true, message: "请输入岗位名称", trigger: "blur" }],
      },
    };
  },
  methods: {
    // 取消新增岗位
    postCancel() {
      this.$emit("postCancel", false);
      this.$message("已取消添加");
    },
    // 确认新增岗位
    addPost() {
      if (this.postList.stationName == "") {
        this.$message({
          message: "请填写岗位名称",
          type: "warning",
        });
      } else {
        this.$emit("addPost", this.postList, false);
        this.postList = { stationName: "" };
      }
    },
  },
};
</script>
<style lang="scss" scoped></style>
